/**
 * 
 */
package com.kunbo.cn.app.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import com.kunbo.cn.app.dao.TransportUnitDao;
import com.kunbo.cn.app.entity.AppUser;
import com.kunbo.cn.app.entity.Car;
import com.kunbo.cn.app.service.TransportUnitService;
/**
 *
 * @author bjl  
 * @date 2019年3月28日 
 */
@Service
public class TransportUnitServiceImpl  implements TransportUnitService{
	@Autowired
	private TransportUnitDao Dao;
	@Autowired
	private JdbcTemplate jdbc;
	
	@Override
	public void save(AppUser tunit) {
		Dao.save(tunit);
	}
	@Override
	public String getTitle(String login_name) {
		String sql="SELECT * from business_customer_users_manage where 1=1";
		sql +=" and login_name =  '" + login_name + "'";
		System.out.println("（*************login_name列表**************）"+login_name);
		List<Map<String, Object>> one = jdbc.queryForList(sql);
		String t = String.valueOf(one.get(0).get("customer").toString());
		
		System.out.println("*************login_name列表**************"+t);
		String sql1 = "SELECT \r\n" + 
				"	s.* \r\n" + 
				"FROM \r\n" + 
				"	business_sale_order_manage s \r\n" + 
				"WHERE   1 = 1 ";
		if(t != null && !t.isEmpty()){
			sql1 += " and s.customerid = '" + t + "'";
		}
		List<Map<String, Object>> list = jdbc.queryForList(sql1);
		String n = String.valueOf(list.get(0).get("customer").toString());
		return n;
	}
	@Override
	public List<Map<String, Object>> TransportList(String login_name,Integer page,Integer pageSize) {
		String sql="SELECT\r\n" + 
				"	c. NAME as customer\r\n" + 
				"FROM\r\n" + 
				"	business_customer_users_manage w,\r\n" + 
				"	business_customer_manage c\r\n" + 
				"WHERE 1 = 1\r\n" + 
				"AND c.id = w.customer";
		sql +=" and w.login_name =  '" + login_name + "'";
		System.out.println("（*************login_name列表**************）"+login_name);
		List<Map<String, Object>> one = jdbc.queryForList(sql);
		String t = String.valueOf(one.get(0).get("customer").toString());//customerid
		String sql1 = "SELECT \r\n" + 
				"	u.* \r\n" + 
				"FROM \r\n" + 
				"	transport_unit_management u \r\n" + 
				"WHERE   1 = 1 ";
		System.out.println("（*************t**************）"+t);
		if(t != null && !t.isEmpty()){
			sql1 += " and u.add_mechanism = '" + t + "'";
		}
		sql1 += " order by id  limit " + (page * pageSize) +"," + pageSize;
		List<Map<String, Object>> list = jdbc.queryForList(sql1);
		return list;
	}
	@Override
	public List<Map<String, Object>> TransDetails(Integer id) {
		String sql="SELECT * from transport_unit_management where id="+id+"";
		List<Map<String, Object>> list = jdbc.queryForList(sql);
		return list;
	}
	@Override
	public void delete(Integer id) {
		Dao.delete(id);
		
	}

}
